<template>
    <el-drawer
        v-model="isShow"
        size="50%"
        :destroy-on-close="true"
        @close="closeHandle"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        :show-close="false"
    >
        <template #header="{ close, titleId, titleClass }">
            <h4 :id="titleId" :class="titleClass">{{ title }}</h4>
        </template>
        <el-form :model="form" label-width="auto" label-position="right" ref="formRef" :rules="rules">
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="案件名称" required prop="name">
                        <el-input v-model="form.name" placeholder="请输入案件名称"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="案件编号">
                        <el-input v-model="form.casecode" placeholder="请输入案件编号"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="案由" >
                        
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="承办人" >
                        <el-input v-model="form.userName" disabled/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button type="primary" @click="submitHandle">提交</el-button>
            <el-button @click="isShow = false">关闭</el-button>
        </template>
    </el-drawer>
</template>

<script setup>
const {proxy} = getCurrentInstance()
// import {getCaseInfoList,getCaseInfoInfo} from "@/api/CaseInfo/CaseInfo";

// 是否显示抽屉
const isShow = ref(false)
// 抽屉标题
const title = ref('')
const rules = {
    name: [{ required: true, message: "案件名称不能为空", trigger: "blur" }],
    unitId: [{ required: true, message: "办案单位不能为空", trigger: "blur" }],
    depid: [{ required: true, message: "办案部门不能为空", trigger: "blur" }],
}

const isAdd = ref(true)

const form = ref({
    
})
// 通知事件
const emit = defineEmits(['getCaseList'])


const changeShowStatus = () => {
    isShow.value = !isShow.value
}

onMounted(() => {
    
})

const showAddEditCase = () => {
    title.value = '新增案件';
    isAdd.value = true
    changeShowStatus()
}

const showEditCase = async (data) => {
    title.value = '修改案件信息'
    isAdd.value = false
    // 对传过来的案由中文进行查找出其对应的casebriefId值
    // await getCaseInfoInfo(data.caseCaseinfoId).then(res => {
    //         form.value = res.data
    //         getDepartment()
    //     })
    changeShowStatus()
}

defineExpose({showAddEditCase,showEditCase})


const submitHandle = async () => {
    proxy.$refs["formRef"].validate(valid => {
        if (valid) {
            if (form.value['caseCaseinfoId']) {
                editCaseInfo(form.value).then(res => {
                    changeShowStatus()
                    emit('getCaseList', '来了老弟')
                })
            } else {
                createCaseInfo(form.value).then(res => {
                    changeShowStatus()
                    emit('getCaseList', '来了老弟')
                })
            }
        }
    });
}

// 关闭后的回调事件
const closeHandle = () => {
    form.value = {
        
    }
}
</script>

<style lang="scss" scoped>
h4{margin:0;}
:deep() .el-date-editor {
  width: 100%;
}
:deep() .el-cascader{width: 100%;}
</style>